package com.chuanyekeji.aokai.Controller;

import com.chuanyekeji.aokai.Entity.LoginLog;
import com.chuanyekeji.aokai.Entity.Product;
import com.chuanyekeji.aokai.Mapper.LoginLogMapper;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@CrossOrigin(origins = "*",maxAge = 3600)
@RestController
public class LoginLogController {

    @Autowired
    LoginLogMapper loginLogMapper;

    /**
     * 获取日志列表
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("getLoginLog")
    String getLoginLog(@RequestParam(required=false,defaultValue="1") int page, @RequestParam(required=false,defaultValue="10") int rows) {
        int lastRow = rows * page;
        int indexRow = lastRow - rows;
        List<LoginLog> loginLogList = loginLogMapper.getLoginLogList(indexRow,lastRow);
        Map<String,Object> data = new HashMap<>();
        data.put("total",loginLogMapper.getLoginLogCount());
        data.put("rows",loginLogList);
        return new Gson().toJson(data);
    }
}
